package 栈;

import java.util.Stack;

/**
 * @Author：小鹿爱吃鱼
 * @Date: 2025/5/8 21:41
 * @Description:
 */
public class 最小栈 {


    private Stack<Integer> data = new Stack<>();
    private Stack<Integer> min = new Stack<>();

    public 最小栈() {

    }

    public void push(int val) {
        data.push(val);
        if(min.isEmpty()) {
            min.push(val);
        }else{
            if(val < min.peek()) {
                min.push(val);
            }else{
                min.push(min.peek());
            }
        }
    }

    public void pop() {
        data.pop();
        min.pop();
    }

    public int top() {
        return data.peek();
    }

    public int getMin() {
        return min.peek();
    }

}
